﻿#region 命名空间

using System.IO;
using System.Reflection;

#endregion

namespace Sharp.Infrastructure
{
    /// <summary>
    ///     资源文件帮助类
    /// </summary>
    public class ResHelper
    {
        /// <summary>
        ///     取得资源
        /// </summary>
        /// <param name="dll">dll的地址</param>
        /// <param name="resourceFullName">资源文件,要包括命名空间和文件的后缀名</param>
        /// <returns></returns>
        /// <remarks>
        ///     调用例子：ResHelper.GetResourceContents("TopWinCMS.Common",
        ///     "TopWinCMS.Common.PageBase.ValidatorUpdateDisplay.res");
        /// </remarks>
        public static string GetResourceContents(string dll, string resourceFullName)
        {
            Stream stream1 = Assembly.Load(dll).GetManifestResourceStream(resourceFullName);

            using (StreamReader reader1 = new StreamReader(stream1))
            {
                return reader1.ReadToEnd();
            }
        }


        /// <summary>
        ///     取得资源
        /// </summary>
        /// <param name="dll">dll的地址</param>
        /// <param name="resourceFullName">资源文件,要包括命名空间和文件的后缀名</param>
        /// <returns></returns>
        /// <remarks>
        ///     调用例子：ResHelper.GetResourceContents("TopWinCMS.Common", "TopWinCMS.Common.PageBase.ValidatorUpdateDisplay.res");
        ///     用完需要关闭 reader。
        /// </remarks>
        public static StreamReader GetResourceStreamReader(string dll, string resourceFullName)
        {
            Stream stream1 = Assembly.Load(dll).GetManifestResourceStream(resourceFullName);

            StreamReader reader1 = new StreamReader(stream1);

            return reader1;
        }
    }
}